package com.sds.fw.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.sds.fw.util.DBUtil;

/**
 * A class providing default implementations for the user-made DAO classes.
 * 
 * @author SDS
 */
public abstract class AbDao {
	/**
	 * returns the connection object using the static method of the DBUtil class,
	 * <code>DBUtil.getConnection()</code>.
	 * 
	 * @return the connection object.
	 */
	public Connection connect() {
		Connection conn = null;
		try {
			conn = DBUtil.getConnection();
		} catch (RuntimeException ex) {
			throw ex;
		}
		return conn;
	}

	/**
     * closes the connection.
     *
     * @param     conn    the Connection object.
     * @param     ps      the PreparedStatement object.
     */
	public void close(Connection conn, PreparedStatement ps) {
		if (ps != null) {
			try {
				ps.close();
			} catch (Exception ex) {
			}
		}

		if (conn != null) {
			try {
				conn.close();
			} catch (Exception ex) {
			}
		}
	}

	/**
     * closes the connection.
     *
     * @param     conn    the Connection object.
     * @param     ps      the PreparedStatement object.
     * @param     rs      the ResultSet object.
     */
	public void close(Connection conn, PreparedStatement ps, ResultSet rs) {
		if (rs != null) {
			try {
				rs.close();
			} catch (Exception ex) {
			}
		}
		close(conn, ps);
	}
}
